jQuery.fn.countDown = function (a, b) {
  a = jQuery.extend({
    duration: 1000,
    startNumber: 10,
    endNumber: 0,
    callBack: function () {}
  }, a);
  return this.each(function () {
    if (!b && b != a.endNumber) {
      b = a.startNumber
    }
    $(this).text(b);
    $(this).animate({
      opacity: 1,
    }, a.duration, '', function () {
      if (b > a.endNumber + 1) {
        $(this).text(b - 1).countDown(a, b - 1)
      } else {
        a.callBack(this)
      }
    })
  })
}; /*! * jQuery Cookie Plugin * https://github.com/carhartl/jquery-cookie * Copyright 2011, Klaus Hartl */
(function ($) {
  $.cookie = function (a, b, c) {
    if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(b)) || b === null || b === undefined)) {
      c = $.extend({}, c);
      if (b === null || b === undefined) {
        c.expires = -1
      }
      if (typeof c.expires === 'number') {
        var d = c.expires,
          t = c.expires = new Date();
        t.setDate(t.getDate() + d)
      }
      b = String(b);
      return (document.cookie = [encodeURIComponent(a), '=', c.raw ? b : encodeURIComponent(b), c.expires ? '; expires=' + c.expires.toUTCString() : '', c.path ? '; path=' + c.path : '', c.domain ? '; domain=' + c.domain : '', c.secure ? '; secure' : ''].join(''))
    }
    c = b || {};
    var e = c.raw ?
    function (s) {
      return s
    } : decodeURIComponent;
    var f = document.cookie.split('; ');
    for (var i = 0, pair; pair = f[i] && f[i].split('='); i++) {
      if (e(pair[0]) === a) return e(pair[1] || '')
    }
    return null
  }
})(jQuery); 
/*! * Name: Marx Popup And Modal * Author: Martin Pham * Version: 1.0.2 * Email: marxvn@gmail.com * Copyright (c) 2012 Martin Pham * Plugin: countDown, Cookie * Dual licensed under the MIT and GPL licenses. */
(function ($) {
  $.marxPAM = (function (c) {
    var c = $.extend({
      time: 60,
      link: [],
      cookie: '__utmk',
      modal: ''
    }, c);
    var e = function () {
        if (typeof is_modal != 'undefined' && $.cookie(c.cookie) == null) {
          if (is_modal) _setmodal()
        }
        $(document.body).live('click', function () {
          _pop()
        })
      };
    function _setmodal() {
      var b = '<div class="wrap"><div class="mx-head"><div class="mx-label">Advertisement</div><div id="mx-ctrl" class="mx-ctrl">Please wait <span id="mx-count"></span> seconds</div></div><div class="mx-content">' + c.modal + '</div></div>';
      $(document.body).css('overflow', 'hidden').append('<div id="mx-modal" class="mx-modal">' + b + '</div>');
      $('#mx-count').countDown({
        startNumber: 3,
        callBack: function (a) {
          $('.mx-label').text('Thanks you for wait! Click [x] to continue...');
          $(a).parent().html('<div id="md-close" class="mt-bt">CLOSE <span>[x]</span></div>');
          $('#md-close').live('click', function () {
            _md_destroy()
          })
        }
      })
    }
    function _md_destroy() {
      $('#mx-modal').remove();
      $('body').css('overflow', 'auto')
    }
    function _ck() {
      var d = new Date();
      d.setTime(d.getTime() + (c.time * 60 * 1000));
      $.cookie(c.cookie, "1", {
        expires: d,
        path: '/',
        domain: '.topphimtuan.com'
      })
    }
    function _pop() {
      if ($.cookie(c.cookie) == null) {
        $.each(c.link, function (i, a) {
          _mwp(a)
        });
        _ck()
      }
    }
    function _mwp(a) {
      var param = '';
      if (!a.same) {
        param = 'width=' + a.width + ',height=' + a.height;
		if(a.crazy){
			var ww = $(window).width(), wh = $(window).height();
			param += ',left='+_rn(ww)+'px,top='+_rn(wh)+'px';
		}
      }
      window.open(a.url, _rn(1000)+'marxvn', param).blur();
      window.focus()
    }
	function _rn(m) {
		return Math.floor(Math.random()*m);
	}
    return e()
  })
})(jQuery);



$.marxPAM({
  time: 60,
  link: [{
    url: "http://www.bay68.com/",
    width: 100,
    height: 100,
	crazy: true,
    same: false
  },
  {
	url: "",width: 100,height: 100,same: false,crazy: true
  },
  {
    url: "",
    same: true
  }, {
    url: "http://www.topphimtuan.com",
    same: false,
    width: 800,
    height: 600,
  }],
  modal: '<a class="mx-link" href="/advertisers"></a>'
});